import java.io.File;
import java.util.Scanner;

public class IODemo7 {
    public static void main(String[] args) {
        //输入必要的信息 要查找的路径和文件名
        Scanner scanner=new Scanner(System.in);
        //file
        System.out.print("please input file name:");
        String fileName = scanner.next();
        //path
        System.out.println("please input path:");
        String rootPath = scanner.next();
        File rootFile=new File(rootPath);

        if(!rootFile.isDirectory()){
            System.out.println("输入路径有错误！");
            return;
        }

        //递归查询
        scanDir(rootFile,fileName);
    }

    //递归查询逻辑
    static void scanDir(File rootFile,String fileName) {
        File[] files=rootFile.listFiles();
        if(files==null){
            return;
        }

        for(File f : files){
            if(f.isFile()){
                System.out.println("current file：" + f.getAbsolutePath());
                if(f.getName().equals(fileName)){
                    System.out.println("找到了 "+f.getAbsolutePath());
                }
            } else if (f.isDirectory()) {
                scanDir(f,fileName);
            }else {

            }
        }
    }
}